class Solution {
public:
    int medianSearch(vector<int>& nums1 , vector<int>& nums2) {
        int n1=nums1.size(), n2=nums2.size();
        int l1=0, r1=n1-1, l2=0, r2=n2-1, mid1, mid2;
        while(l1<r1)
        {
            mid1=(l1+r1)>>1, mid2=(l2+r2)>>1; //向上取整
            if(nums1[mid1]==nums2[mid2]) return nums1[mid1];
            bool odd=(r1-l1+1)%2==1;
            if(nums1[mid1]<nums2[mid2]) l1=odd?mid1:mid1+1, r2=mid2;
            else l2=odd?mid2:mid2+1, r1=mid1;
            
        } 
        return min(nums1[l1], nums2[l2]);  
    }
};